package com.suse.warmstill.controller;

import com.suse.warmstill.common.model.CallResult;
import com.suse.warmstill.common.model.ListPageModel;
import com.suse.warmstill.entity.TbDoctor;
import com.suse.warmstill.mapper.TbDoctorMapper;
import com.suse.warmstill.service.DOkerWxService;
import com.suse.warmstill.vo.ConditionVO;
import com.suse.warmstill.vo.DockerIndexVo;
import com.suse.warmstill.vo.DockerWxVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 黄靖
 * @author 2022-11-05 13:05
 * description:
 **/
@RestController
@Api(tags = "pc的医生管理")
@RequestMapping("/pc/dockers")
public class PCDockerApi {
    @Resource
    private DOkerWxService dOkerService;

    @Resource
    private TbDoctorMapper doctorMapper;


    @GetMapping("/list")
    @ApiOperation("首页查询所有的首页医生")
    public CallResult<ListPageModel<DockerIndexVo>> list(@Validated ConditionVO conditionVO) {
        ListPageModel<DockerIndexVo> list = dOkerService.list(conditionVO);

        return CallResult.success(list);
    }

    @GetMapping("/getOne")
    @ApiOperation("查询单个的首页医生")
    public CallResult<DockerWxVo> getOne(@RequestParam Integer id) {

        DockerWxVo docker = dOkerService.getOne(id);
        return CallResult.success(docker);
    }

    @ApiOperation("新增用户,逻辑删除 写 0")
    @PostMapping("/add")
    public CallResult addDocker(@RequestBody TbDoctor doctor) {
        doctor.setIsDel("0");

        doctorMapper.insert(doctor);

        return CallResult.success();
    }

    @ApiOperation("修改医生,需要传id")
    @PostMapping("updateDocker")
    public CallResult updateDocker(@RequestBody TbDoctor doctor){
        return CallResult.success(doctorMapper.updateById(doctor));
    }

    @DeleteMapping("/delete/{id}")
    public CallResult deleteDocker(@PathVariable Integer id) {

        return CallResult.success(doctorMapper.deleteById(id));
    }
}
